package com.wlcj.www.model.main;

import java.util.List;

import com.jfinal.plugin.activerecord.Model;
import com.wlcj.util.SqlUtil;

public class Channel extends Model<Channel> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7085613198771636975L;
	
	public static final Channel dao = new Channel();
	
	public List<Channel> getTopChannels() {
		String sql = "select * from jc_channel where parent_id is null and is_display = 1 order by priority asc";
		return find(sql);
	}
	public List<Channel> getParentChannelById(Integer channelId){
		return find(SqlUtil.sql("channel.getAllParentChannel"),channelId);
	}
	/**
	 * 根据栏目栏目id获取父级栏目id
	 * @param channelPath
	 * @return
	 */
	public Channel getChannelByChannelId(Integer channelId){
		return findFirst("select * from jc_channel where channel_id = ?",channelId);
	}
	public Channel getChannelByPath(String channelPath){
		return findFirst("select * from jc_channel where channel_path = ?",channelPath);
	}
	public List<Channel> getChannelsByParentId(int id){
		String sql = "select j.*,e.* from jc_channel j,jc_channel_ext e where j.channel_id = e.channel_id and j.channel_id > 180 and parent_id = ? and is_display = 1 order by priority asc";
		return find(sql,id);
	}
}
